<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>SelectProgram</title>
    <!--<link href="../../../webjar/bootstrap/3.3.7-1/css/bootstrap.min.css" rel="stylesheet">-->
    <link href="../../../webjar/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="../../../webjar/css/mystyle.css" rel="stylesheet">
    <link rel="stylesheet" media="all" type="text/css" href="CSS/workflow.css" />

    <script src="../../../webjar/jquery/3.1.1/jquery.min.js"></script>
    <script src="../../../webjar/bootstrap/3.3.7-1/js/bootstrap.min.js"></script>
    <script src="../../../webjar/bootstrap-table/bootstrap-table.min.js"></script>

</head>
<body>
<form class="form-horizontal" role="form" style="padding:15px;">
    <div class="form-group" style="margin-bottom:5px;">
        <div class="col-xs-9">
            <input type="text" class="form-control" id="txtPSCcontent" placeholder="请输入一段文字描述程序信息">
        </div>
        <div class="col-xs-3">
            <button type="button" id="PSCSearch" class="btn btn-custom" style="width:100%;">搜索</button>
        </div>
    </div>
    <div class="form-group" style="padding:15px">
        <div class="bootstrap-table table">
            <div class="table-responsive">
                <!--<table id="PSCresultTable" data-toggle="table" data-click-to-select="true" data-striped="true" data-height="150" data-row-style="rowStyle" data-cell-style="cellStyle" data-unique-id="id">
                    <thead>
                        <tr>
                            <th data-field="state" data-radio="true"></th>
                            <th data-field="id" data-visible="false"></th>
                            <th data-field="code">代码</th>
                            <th data-field="name">名称</th>
                            <th data-field="version">版本</th>
                        </tr>
                    </thead>
                </table>-->

                <table id="PSCresultTable" class="bootstrap-table table"
                       data-toggle="table"
                       data-click-to-select="true"
                       data-striped="true"
                       data-row-style="rowStyle"
                       data-cell-style="cellStyle"
                       data-height="260">
                    <thead>
                    <tr>
                        <th data-field="state" data-radio="true"></th>
                        <th data-field="id" data-visible="false"></th>
                        <th data-field="code">代码</th>
                        <th data-field="name">名称</th>
                        <th data-field="version">版本</th>
                        <th data-field="description">备注</th>
                    </thead>
                </table>
            </div>
        </div>
    </div>
    <div class="form-group" style = "margin-bottom: 0px">
        <div class="col-xs-6 col-xs-offset-1" style="text-align: right">
            <button type="button" id="PSCconfirm" class="btn btn-info">确定</button>
        </div>
    </div>
</form>
<script type="text/javascript">
    $(function(){
        if(workFlowId){
            initFunctions();
        }
    });

    function initFunctions(){
        'use strict';
        //加载表格数据
        var StepCheckUrl = serverPath + "craftProcess/findValidCraftProcess";
        var datas = {'str':""};
        $.ajax({
            url: StepCheckUrl,
            data: datas,
            xhrFields:{ withCredentials:true},
            dataType: "json",
            //async: false,
            success: function (result) {
                var data = result.data;
                console.log(data);
                $("#PSCresultTable").bootstrapTable('load', data);
            },
            error: function () {
                alert('未能加载步骤信息');
            }
        });

        //表格事件处理
        $('#PSCresultTable').on('check.bs.table', function (e, row){
            //拿到行选中的数据
            var wfcode = row["code"];
            var wfname = row["name"];
            var wfversion = row["version"];
            var wfid = row["id"];
            var wfdescribe = row["description"];
            var data = [wfcode, wfname, wfversion, wfid, wfdescribe];
            $('#ProgramInfo').attr('ibcdata',data);
            $('#PSCconfirm').on('click', function(){
                $('#ProgramInfo').val(wfcode + wfname);
                ibcpLayer.Close(index);
            });
        });

        //查找按钮事件
        $('#PSCSearch').on('click',function(){
            var $val = $('#txtPSCcontent').val();
            findStepData($val);
        });
    }

    //查找数据按钮功能
    function findStepData(str){
        var checkDatasUrl = serverPath + "craftProcess/findValidCraftProcess";
        var datas = {'str':str,'statusId':3};
        ibcpAjax.Select(checkDatasUrl,datas,true,function(result){
            var data = result.data;
            $('#PSCresultTable').bootstrapTable('load', data);
            if(data.length >0) {
                //设置选中行
                $('#PSCresultTable').bootstrapTable('check', 0);
            }
        });
    }
</script>
</body>
</html>